package com.jgjc.controller;

import com.jgjc.service.BasicInfoService;
import com.jgjc.service.FramingInfoService;
import com.jgjc.utils.ResultResUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Slf4j
public class FramingInfoController {

    @Resource
    private FramingInfoService framingInfoService;

    @Resource
    private BasicInfoService basicInfoService;


    @GetMapping(value = "/bridge/bridgeSide/getBridgeList")
    public Map<String, Object> getBridgeList(HttpServletRequest request) {
        int pageSize = Integer.valueOf(request.getParameter("pageSize"));
        int currentPage = Integer.valueOf(request.getParameter("currentPage"));
        List<Map<String, Object>> listMap = basicInfoService.getAllBasicInfo("");
        Map<String, Object> map = new HashMap<>();
        map.put("currentPage", currentPage);
        map.put("data", listMap);
        map.put("pageSize", pageSize);
        map.put("total", listMap.size());
        return map;
    }

    @GetMapping(value = "/bridge/bridgeSide/getSideTypeList")
    public List<Map<String, Object>> getSideTypeList() {
        List<Map<String, Object>> listMap = framingInfoService.getSideTypeList();
        return listMap;
    }

    @GetMapping(value = "/bridge/bridgeSide/getAccessLinearList")
    public List<Map<String, Object>> getAccessLinearList() {
        List<Map<String, Object>> listMap = framingInfoService.getAccessLinearList();
        return listMap;
    }

    @GetMapping(value = "/bridge/bridgeSide/getListByBridgeId")
    public List<Map<String, Object>> getListByBridgeId(HttpServletRequest request) {
        int bridgeId = Integer.parseInt(request.getParameter("bridgeId"));
        List<Map<String, Object>> listMap = framingInfoService.getListByBridgeId(bridgeId);
        return listMap;
    }


    @PostMapping(value = "/bridge/bridgeSide/add")
    public Map<String, Object> add(@RequestBody Map<String, Object> map) {
        int code = framingInfoService.add(map);
        Map<String, Object> resultMap = new HashMap<>();
        ResultResUtils.ResultRes(code, resultMap);
        return resultMap;
    }

    @DeleteMapping(value = "/bridge/bridgeSide/delete")
    public Map<String, Object> delete(@RequestBody Map<String, Object> map) {
        int code = framingInfoService.delete((Integer) map.get("id"));
        Map<String, Object> resultMap = new HashMap<>();
        ResultResUtils.ResultRes(code, resultMap);
        return resultMap;
    }

    @PostMapping(value = "/bridge/bridgeSide/edit")
    public Map<String, Object> edit(@RequestBody Map<String, Object> map) {
        int code = framingInfoService.edit(map);
        Map<String, Object> resultMap = new HashMap<>();
        ResultResUtils.ResultRes(code, resultMap);
        return resultMap;
    }

}
